package com.vooda.business_admin.controller.homePage;

import com.vooda.business_admin.common.BaseController;
import com.vooda.business_admin.common.ReqDataTableDto;
import com.vooda.business_admin.common.RspDataTableDto;
import com.vooda.business_admin.entity.HomePage;
import com.vooda.business_admin.service.HomePageService;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * 轮播图
 */
@RestController
@RequestMapping("/homePage")
public class HomePageController extends BaseController{

    @Autowired
    private HomePageService homePageService;

    /**
     * 获取轮播图列表
     * @param dataTableDTO
     * @return
     */
    @GetMapping("/getAllList")
    public RspDataTableDto<HomePage> getAllArticle(ReqDataTableDto dataTableDTO,
                                                   @RequestParam(value = "type",required = false) String type){

       return homePageService.findHomePageList(dataTableDTO,type);

    }

    /**
     *保存轮播图
     * @return
     */
    @PostMapping("/saveHomePage")
    public String saveHomePage(HomePage homePage, @RequestParam(required = false) MultipartFile image){
       return homePageService.saveHomePage(homePage,image);

    }


    /**
     * 修改封面图片
     * @param imageUpload
     * @param id
     * @return
     */
    @PostMapping("/updateImage/{id}")
    public void updateImage(@RequestParam("imageUpload") MultipartFile imageUpload, @PathVariable("id") Long id){

        homePageService.updateImage(imageUpload,id);

    }

    /**
     * 修改状态
     * @param id
     * @return
     */
    @PostMapping("/modifyStatus/{id}")
    public void modifyStatus( @PathVariable("id") Long id){

        homePageService.modifyStatus(id);

    }
}
